//
//  SaoWebViewController.m
//  specialine
//
//  Created by 往返网络 on 17/2/15.
//  Copyright © 2017年 com. All rights reserved.
//

#import "SaoWebViewController.h"

@interface SaoWebViewController ()<UIWebViewDelegate>

@property (strong,nonatomic)NSString *currentURL;
@property (strong,nonatomic)NSString *currentTitle;
@property (strong,nonatomic)NSString *currentHTML;
@end

@implementation SaoWebViewController
{

    UIWebView * webview;
    
}

- (void)viewWillAppear:(BOOL)animated{


    [super viewWillAppear:animated];
    
    
    self.tabBarController.tabBar.hidden = YES;
    
    self.navigationController.navigationBar.barTintColor = COLORRGBA(7, 24, 57, 1);
    
    
    float fontsize = 17;
    
    fontsize = SCREEN_H < 667 ? 15 : 19;
    
    if (SCREEN_H == 667) {
        
        fontsize = 17;
    }
    
    
    //设置导航条
    self.navigationController.navigationBar.barTintColor = COLORRGBA(7, 24, 57, 1);
    
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName :[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:17]};
    
    UIButton * returnbtn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100.0/W_BASE*SCREEN_W, 88.0/H_BASE*SCREEN_H)];
    
    returnbtn1.titleLabel.font = [UIFont fontWithName:@"iconfont" size:fontsize + 5];
    
    [returnbtn1 setTitle:@"\U0000e697" forState:UIControlStateNormal];
    
    [returnbtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    UIBarButtonItem * item1 = [[UIBarButtonItem alloc]initWithCustomView:returnbtn1];
    
    self.navigationItem.leftBarButtonItem = item1;
    
    [returnbtn1 setTitleEdgeInsets:UIEdgeInsetsMake(0,0 , 0, 60.0/W_BASE*SCREEN_W)];
    
    [returnbtn1 addTarget:self action:@selector(enterClick:) forControlEvents:UIControlEventTouchUpInside];
    


}

- (void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];
    
    self.tabBarController.tabBar.hidden = NO;
    
    [self.navigationController popToRootViewControllerAnimated:YES];

    
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self createWebview];
    
    // Do any additional setup after loading the view.
    
}

- (void)createWebview{
    
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
    
    [self.view addSubview:webview ];
    
    webview.delegate = self;
    
    NSURL * URL = [NSURL URLWithString:_urlstring];
    
    NSLog(@"请求的网址为 URL %@",URL);
    
    if (_saomiaotype == 1) {
        
        //二维码,进入webview
        
        NSURLRequest * request = [NSURLRequest requestWithURL:URL];
        
        [webview loadRequest:request];
        
        
    }else{
    
       //条形码，获得数字号
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_W * 0.16, 0.149*SCREEN_H, 0.68*SCREEN_W, SCREEN_W * 0.16)];
        
       // label.backgroundColor = [UIColor grayColor];
        
        [self.view addSubview:label];
        
        label.text = [NSString stringWithFormat:@"获得条形码信息为:%@",_urlstring];
        
        label.numberOfLines = 0;
        
        label.adjustsFontSizeToFitWidth = YES;
        
    
    }
    
}

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    //获取当前页面的title
    self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    
    self.currentURL = webView.request.URL.absoluteString;
    
    NSString *ns = @"document.documentElement.innerHTML";//获取当前网页的html
    
    self.currentHTML = [webView stringByEvaluatingJavaScriptFromString:ns];
    
    
}

- (void)enterClick:(UIButton *)btn{


    [self.navigationController popViewControllerAnimated:YES];
    


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
